package org.budo.shiro.session.dao.jedis;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;

import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.mgt.ValidatingSession;
import org.budo.time.Time;

/**
 * 空的Session
 * 
 * @author li
 * @version 1 (2015年11月10日 上午9:33:32)
 * @since Java7
 */
public class NoSession implements ValidatingSession, Serializable {
    private static final long serialVersionUID = 2578981210611043432L;

    private Serializable sessionId;

    public NoSession(Serializable sessionId) {
        this.sessionId = sessionId;
    }

    public Serializable getId() {
        return sessionId;
    }

    public Date getStartTimestamp() {
        return Time.now().toDate();
    }

    public Date getLastAccessTime() {
        return Time.now().toDate();
    }

    public long getTimeout() throws InvalidSessionException {
        return 0;
    }

    public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException {}

    public String getHost() {
        return null; // null for unknown
    }

    public void touch() throws InvalidSessionException {}

    public void stop() throws InvalidSessionException {}

    @SuppressWarnings("unchecked")
    public Collection<Object> getAttributeKeys() throws InvalidSessionException {
        return Collections.EMPTY_SET;
    }

    public Object getAttribute(Object key) throws InvalidSessionException {
        return null;
    }

    public void setAttribute(Object key, Object value) throws InvalidSessionException {}

    public Object removeAttribute(Object key) throws InvalidSessionException {
        return null;
    }

    public boolean isValid() {
        return false;
    }

    public void validate() throws InvalidSessionException {}
}